/**
 * Kalaisoo
 *
 * A lightweight no-framework framework written in PHP
 *
 * @package Kalaisoo
 * @author $Author: info@sah-company.com $
 */

/**
 * document.ready jquery stuff
 */
$(document).ready(function() {

	/**
	 * all and future detach links send a post request and then
	 * fade out and finally detach the element
	 */
	$('.detach').live('click', function() {
		var target = $(this).attr("data-target");
		var url = $(this).attr("href");
		$.post(url, function(data) {
	        $('#'+target).fadeOut('slow', function() {
				$('#'+target).detach();
			});
	    });
		return false;
	});

	/**
	 * all and future attach links post request a url and
	 * insert a new element into the *-additional zone
	 */
	$('.attach').live('click', function() {
		var target = $(this).attr("data-target");
		var url = $(this).attr("href");
		$.post(url, function(data) {
	        $('#'+target).prepend(data);
	    });
		return false;
	});
	
	/**
	 * all and future unassociate links post request a url and
	 * replace the current relation state
	 */
	$('.unassociate').live('click', function() {
		var target = $(this).attr("data-target");
		var url = $(this).attr("href");
		$.post(url, function(data) {
			$('#'+target).empty();
	        $('#'+target).prepend(data);
	    });
		return false;
	});
	
	/**
	 * all and future associate links post request a url and
	 * replace the current relation state
	 */
	$('.associate').live('click', function() {
		var target = $(this).attr("data-target");
		var url = $(this).attr("href");
		$.post(url, function(data) {
			$('#'+target).empty();
	        $('#'+target).prepend(data);
	    });
		return false;
	});

});